//
//  RBGoodsConfirmChooseCouponPopVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/9/14.
//

#import "RBGoodsConfirmChooseCouponPopVC.h"
#import "RBDefine.h"
#import "UIView+RBAdd.h"
#import "UIScrollView+RBAdd.h"
#import <Masonry.h>
#import "RBThemeConfig.h"
#import <UIColor+YYAdd.h>
#import <UIView+YYAdd.h>
#import "RanTool.h"
#import "RBMyCouponListCell.h"

@interface RBGoodsConfirmChooseCouponPopVC ()<UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout>

@property(nonatomic, strong)UICollectionView *collectionView;
@property(nonatomic, strong)NSMutableArray *dataSource;

@end

@implementation RBGoodsConfirmChooseCouponPopVC

#pragma mark - Lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setup];
}

#pragma mark - Private

- (void)setup
{
    self.contentView = UIView.new;
    [self.view addSubview:self.contentView];
    self.contentView.backgroundColor = UIColor.whiteColor;
    [self.contentView rbSetCorner:UIRectCornerTopLeft | UIRectCornerTopRight radius:Zoom(20)];
    [self.contentView view_addView:[RanTool labelWithFontSize:Zoom(14) weight:0 color:UIColor.blackColor align:0 text:@"优惠券"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(36) bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
    
    UIImageView *closeBtn = [RanTool imgViewWithMode:0 radius:0 imgName:@"goodsDetailPramsClose"];
    [closeBtn extendResponseArea];
    [closeBtn rbAddTapGesWithTarget:self action:@selector(dismiss)];
    [self.contentView addSubview:closeBtn];
    [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(Zoom(18));
        make.top.mas_equalTo(Zoom(22));
        make.right.mas_equalTo(-Zoom(16));
    }];
    
    [self.contentView view_addView:[RanTool labelWithFontSize:Zoom(14) weight:0 color:@"#C1C1C1" align:0 text:@"可用优惠券"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(32) bottom:0 left:Zoom(12) right:Zoom(12) centerX:0];
    
    [self.contentView view_addView:self.collectionView withHeight:Zoom(357) width:kRBMainScreenWidth top:Zoom(22) bottom:MAX(Zoom(22), kRBSafeBottomHeight) left:0 right:0 centerX:0];
    
    self.view.backgroundColor = UIColor.clearColor;
    self.contentView.left = 0;
    self.contentView.width = kRBMainScreenWidth;
    self.contentView.height = self.contentView.esSize.height;
    self.contentView.top = kRBMainScreenHeight;
    
    [self.dataSource addObject:({
        RBGroupModel *group = RBGroupModel.new;
        group.minimumLineSpacing = Zoom(20);
        group.cellModels = ({
            NSMutableArray *arrayM = NSMutableArray.array;
            for (NSInteger i = 0; i < self.data.count; i++)
            {
                [arrayM addObject:({
                    RBCellModel *cellModel = RBCellModel.new;
                    cellModel.reuseCellIdentifier = NSStringFromClass(RBMyCouponListCell.class);
                    cellModel.itemSize = CGSizeMake(kRBMainScreenWidth, Zoom(88));
                    cellModel.cellData = self.data[i];
                    cellModel;
                })];
            }
            arrayM;
        });
        group;
    })];
    [self.collectionView reloadData];
}

- (void)show
{
    [UIView animateWithDuration:0.15 animations:^{
        self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
        self.contentView.bottom = kRBMainScreenHeight;
    }];
}

- (void)dismiss
{
    [UIView animateWithDuration:0.15 animations:^{
        self.view.backgroundColor = UIColor.clearColor;
        self.contentView.top = kRBMainScreenHeight;
    } completion:^(BOOL finished) {
        [self dismissViewControllerAnimated:NO completion:nil];
    }];
}

#pragma mark - Network

#pragma mark - Event

#pragma mark - UICollectionViewDataSource & UICollectionViewDelegate

kRBCollectionViewDataSourceAndDelegate(self.dataSource);

#pragma mark - Setter

#pragma mark - Getter

- (UICollectionView *)collectionView
{
    if (!_collectionView)
    {
        self.collectionView = ({
            UICollectionViewFlowLayout *layout = UICollectionViewFlowLayout.new;
            UICollectionView *view = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
            view.showsVerticalScrollIndicator = NO;
            view.showsHorizontalScrollIndicator = NO;
            view.dataSource = self;
            view.delegate = self;
            view.backgroundColor = UIColor.clearColor;
            kRBIgnoreScrollViewInsetsAdjust(view);
            view;
        });
    }
    return _collectionView;
}

- (NSMutableArray *)dataSource
{
    if (!_dataSource)
    {
        self.dataSource = ({
            NSMutableArray *arrayM = NSMutableArray.array;
            arrayM;
        });
    }
    return _dataSource;
}


@end
